<template><div><h1 id="淘宝镜像" tabindex="-1"><a class="header-anchor" href="#淘宝镜像" aria-hidden="true">#</a> 淘宝镜像</h1>
<div class="custom-container tip">
<p class="custom-container-title">安装NodeJS之后使用npm来安装包使用的是国外的地址，经常会出现超时错误，可以通过修改为国内的淘宝源来加速安装</p>
</div>
<h3 id="配置" tabindex="-1"><a class="header-anchor" href="#配置" aria-hidden="true">#</a> 配置</h3>
<h4 id="临时使用" tabindex="-1"><a class="header-anchor" href="#临时使用" aria-hidden="true">#</a> 临时使用</h4>
<div class="language-javascript ext-js line-numbers-mode"><pre v-pre class="language-javascript"><code>npm <span class="token operator">--</span>registry https<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span>registry<span class="token punctuation">.</span>npm<span class="token punctuation">.</span>taobao<span class="token punctuation">.</span>org install express 
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div></div></div><h3 id="永久使用" tabindex="-1"><a class="header-anchor" href="#永久使用" aria-hidden="true">#</a> 永久使用</h3>
<h4 id="直接配置" tabindex="-1"><a class="header-anchor" href="#直接配置" aria-hidden="true">#</a> 直接配置</h4>
<div class="language-javascript ext-js line-numbers-mode"><pre v-pre class="language-javascript"><code>npm config <span class="token keyword">set</span> registry https<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span>registry<span class="token punctuation">.</span>npm<span class="token punctuation">.</span>taobao<span class="token punctuation">.</span>org
通过如下命令可以查看是否配置成功
npm config <span class="token keyword">get</span> registry
<span class="token literal-property property">如果需要恢复成原来的官方地址只需要执行如下命令</span><span class="token operator">:</span>
npm config <span class="token keyword">set</span> registry https<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span>registry<span class="token punctuation">.</span>npmjs<span class="token punctuation">.</span>org
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="使用cnpm" tabindex="-1"><a class="header-anchor" href="#使用cnpm" aria-hidden="true">#</a> 使用cnpm</h3>
<div class="language-javascript ext-js line-numbers-mode"><pre v-pre class="language-javascript"><code>安装淘宝的cnpm，然后在使用时直接将npm命令替换成cnpm命令即可
npm install <span class="token operator">-</span>g cnpm <span class="token operator">--</span>registry<span class="token operator">=</span>https<span class="token operator">:</span><span class="token operator">/</span><span class="token operator">/</span>registry<span class="token punctuation">.</span>npm<span class="token punctuation">.</span>taobao<span class="token punctuation">.</span>org
然后安装时使用如下命令
cnpm install axios
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h3 id="nrm-切换npm源-淘宝镜像" tabindex="-1"><a class="header-anchor" href="#nrm-切换npm源-淘宝镜像" aria-hidden="true">#</a> nrm 切换npm源 淘宝镜像</h3>
<div class="language-javascript ext-js line-numbers-mode"><pre v-pre class="language-javascript"><code>下载 nrm ：    npm i nrm
查询 列表 ：   nrm ls
切换源 ：      nrm use npm
在切换回淘宝 ： nrm use taobao
测试源的速度：  nrm test npm
</code></pre><div class="line-numbers" aria-hidden="true"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div></div></template>


